﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EBookStore.Books;
using EBookStore.Users;
using System.Drawing;
using EBookStore.Payments;

namespace EbookStoreUnitTest.Utils
{
    static class ObjectsGenerator
    {

        /// <summary>
        /// Generates books
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<EBookStore.Books.Book> GenerateBooks(int amount)
        {
            List<EBookStore.Books.Book> books = new List<Book>();
            Random rand = new Random((int)DateTime.Now.Ticks);
            int ISBN = rand.Next(100000, 999999);


            for (int i = 0; i < amount; i++)
            {
                Book b = new Book((ISBN + i).ToString());
                b.Pages = rand.Next(100, 500);
                b.Price = (decimal)Math.Round(rand.NextDouble(), 2) * rand.Next(5, 50);
                b.Subtitles = Convert.ToBoolean(rand.Next(0, 1));
                b.Title = string.Format("Book_{0}", i + 1);
                b.TypicalShippingTime = new TimeSpan(rand.Next(100000, 999000));
                books.Add(b);
            }
            return books.ToArray();
        }

        /// <summary>
        /// Generates two Clerks and others are Customers
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<User> GenerateCustomers(int amount)
        {
            List<User> users = new List<User>();
            for (int i = 0; i < amount; i++)
            {
                User u = null;
                u = new Customer(string.Format("Customer_fName_{0}", i + 1),
                    string.Format("Customer_lName_{0}", i + 1),
                    string.Format("Customer_address_{0}", i + 1));
                users.Add(u);

            }
            return users.ToArray();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="amount"></param>
        /// <returns></returns>
        public static IEnumerable<User> GenerateClerks(int amount)
        {
            List<User> users = new List<User>();
            for (int i = 0; i < amount; i++)
            {
                User u = null;
                u = new Clerk("", "", string.Format("Clerk_fName_{0}", i + 1),
                    string.Format("Clerk_lName_{0}", i + 1));
                users.Add(u);
            }
            return users.ToArray();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static EBookStore.Payments.Payment[] CreateCheckPayment(int amount)
        {
            List<Payment> list = new List<Payment>();
            EBookStore.Payments.PaymentFactory f = new PaymentFactory();
            for (int i = 0; i < amount; i++)
            {
                Bitmap bmp = new Bitmap(10, 10);
                Payment payment = f.CreateCheckPayment();
                ((CheckPayment)payment).CheckImage = bmp;
                payment.Sum = 100;
                payment.FirstPayment = 100;
                payment.Payments = 1;
                list.Add(payment);
            }


            return list.ToArray();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="amount"></param>
        /// <returns></returns>
        public static EBookStore.Payments.Payment[] CreateCreditCardPayment(int amount)
        {
            List<Payment> list = new List<Payment>();
            EBookStore.Payments.PaymentFactory f = new PaymentFactory();
            for (int i = 0; i < amount; i++)
            {
                Payment payment = new CreditCardPayment("123", eCreditCard.AmericanExpress);
                payment.Sum = 120;
                payment.FirstPayment = 120;
                payment.Payments = 1;
                list.Add(payment);
            }
            return list.ToArray();
        }

    }
}
